package com.sxt.sys.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxt.sys.domain.User;
import com.sxt.sys.service.UserService;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.utils.ResultObj;
import com.sxt.sys.vo.UserVo;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 阿刘
 * @since 2019-04-25
 */
@RestController
public class UserController {
	private static final String MODEL="user/";
	
	@Autowired
	private UserService userService;
	
	/**
	 * 加载所有用户
	 */
	@RequestMapping(MODEL+"loadAllUser")
	public DataGridView loadAllUser(UserVo userVo) {
		return this.userService.queryAllUser(userVo);
	} 
	
	/**
	 * 添加用户
	 */
	@RequestMapping(MODEL+"addUser")
	public ResultObj addUser(UserVo userVo) {
		try {
			this.userService.addDept(userVo);
			return ResultObj.addOk();
		} catch (Exception e) {
			return ResultObj.addError();
		}
	}
	
	/**
	 * 修改用户
	 */
	@RequestMapping(MODEL+"updateUser")
	public ResultObj updateUser(UserVo userVo) {
		try {
			this.userService.updateUser(userVo);
			return ResultObj.updateOk();
		} catch (Exception e) {
			return ResultObj.updateError();
		}
	}
	
	/**
	 * 删除用户
	 */
	@RequestMapping(MODEL+"deleteUser")
	public ResultObj deleteUser(UserVo userVo) {
		try {
			this.userService.deleteUser(userVo);
			return ResultObj.deleteOk();
		} catch (Exception e) {
			return ResultObj.deleteError();
		}
	}
	
}

